import type { App } from "vue";
import { RouteRecordRaw, createRouter, createWebHistory } from "vue-router";
import { basicRoutes, useAddDynamicRoutes } from "./routes";
import { setupRouterGuard } from "./guard";

export const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_BASE_URL),
  routes: basicRoutes as RouteRecordRaw[],
  scrollBehavior() {
    return { left: 0, top: 0 };
  },
});

export const { addDynamicRoutes, resetRouter } = useAddDynamicRoutes(router);

/** setup vue router. - [安装vue路由] */
export async function setupRouter(app: App) {
  await addDynamicRoutes();
  setupRouterGuard(router);
  app.use(router);
}
